package ym.ecrm.core.domain.systemManagement;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ym.ecrm.core.domain.base.BaseEntity;
import ym.ecrm.core.domain.customerManagement.Customer;

/**
 * 用户类
 * @author Princess
 * @version 1.0
 */
@Entity
@Table(name = "t_user")
public class User extends BaseEntity {


	/**
	 * userName 用户名，也叫用户登陆名
	 */
	private String userName;
	/**
	 * realName 真实姓名
	 */
	private String realName;
	/**
	 * password 密码，新增用户默认密码是用户名
	 */
	private String password;
	/**
	 * userCode 用户编号
	 */
	private String userCode;
	/**
	 * state 状态
	 */
	private String state;
	/**
	 * phone 电话号码,即固话
	 */
	private String phone;
	/**
	 * mobilePhone 移动电话
	 */
	private String mobilePhone;
	/**
	 * emailAddress 电子邮件
	 */
	private String emailAddress;
	/**
	 * enabled 是否可用
	 */
	private Boolean enabled;
	/**
	 * builtIn 是否为内置，内置即系统原本的就有的，不可删除
	 */
	private Boolean builtIn;
  /**
   * 和 Role 角色多对多关联
   */
	@ManyToMany(targetEntity = Role.class, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE }, fetch = FetchType.EAGER)
	@JoinTable(name = "tr_user_role", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
	private Set<Role> roles = new HashSet<Role>();

	/**
	 * 和 Organization 组织机构多对一关联
	 */
	@ManyToOne(targetEntity = Organization.class, cascade = {
			CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name = "tr_organization_user", 
			joinColumns = @JoinColumn(name = "userId"), 
			inverseJoinColumns = @JoinColumn(name = "organizationId"))
	private Organization organization;
	
	/**
	 * 和客户一对多关联
	 */
	@OneToMany(targetEntity=Customer.class
				,cascade = {CascadeType.PERSIST,CascadeType.MERGE}
				,fetch =FetchType.EAGER )
	@JoinColumn(name ="userId")
	private Set<Customer> customers = new HashSet<Customer>();

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserCode() {
		return userCode;
	}

	public void setUserCode(String userCode) {
		this.userCode = userCode;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public Boolean getBuiltIn() {
		return builtIn;
	}

	public void setBuiltIn(Boolean builtIn) {
		this.builtIn = builtIn;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobilePhone() {
		return mobilePhone;
	}

	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

}
